home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 0361 / atomic.frm < prev    next >
Text File  |  1997-03-31  |  18KB  |  554 lines

  1. VERSION 2.00
  2. Begin Form Atomic 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Call the Atomic Clock"
  6.    ClientHeight    =   3975
  7.    ClientLeft      =   2475
  8.    ClientTop       =   945
  9.    ClientWidth     =   4695
  10.    ClipControls    =   0   'False
  11.    Height          =   4410
  12.    Left            =   2400
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   3975
  17.    ScaleWidth      =   4695
  18.    Top             =   585
  19.    Width           =   4845
  20.    Begin MSComm Comm1 
  21.       InBufferSize    =   2048
  22.       Interval        =   1000
  23.       Left            =   3390
  24.       NullDiscard     =   -1  'True
  25.       OutBufferSize   =   2048
  26.       RTSEnable       =   -1  'True
  27.       Top             =   1125
  28.    End
  29.    Begin SSCheck DST 
  30.       Caption         =   "Use Daylight Savings Time"
  31.       Height          =   285
  32.       Left            =   225
  33.       TabIndex        =   4
  34.       Top             =   960
  35.       Width           =   2640
  36.    End
  37.    Begin ComboBox TimeZone 
  38.       BackColor       =   &H00FFFFFF&
  39.       Height          =   300
  40.       Left            =   375
  41.       Style           =   2  'Dropdown List
  42.       TabIndex        =   3
  43.       Top             =   450
  44.       Width           =   4065
  45.    End
  46.    Begin CommandButton Command1 
  47.       Cancel          =   -1  'True
  48.       Caption         =   "Cancel"
  49.       Height          =   345
  50.       Index           =   2
  51.       Left            =   2370
  52.       TabIndex        =   1
  53.       Top             =   3300
  54.       Width           =   2085
  55.    End
  56.    Begin CommandButton Command1 
  57.       Caption         =   "Dial"
  58.       Default         =   -1  'True
  59.       Height          =   345
  60.       Index           =   1
  61.       Left            =   2370
  62.       TabIndex        =   0
  63.       Top             =   2790
  64.       Width           =   2070
  65.    End
  66.    Begin CommandButton Command1 
  67.       Caption         =   "Reset Defaults"
  68.       Height          =   345
  69.       Index           =   0
  70.       Left            =   2370
  71.       TabIndex        =   12
  72.       Top             =   2280
  73.       Width           =   2070
  74.    End
  75.    Begin SSFrame Frame3D1 
  76.       Caption         =   "COM Port"
  77.       ForeColor       =   &H00000000&
  78.       Height          =   1530
  79.       Left            =   255
  80.       TabIndex        =   7
  81.       Top             =   2190
  82.       Width           =   1965
  83.       Begin SSOption ComPort 
  84.          Caption         =   "COM&4:"
  85.          ForeColor       =   &H00000000&
  86.          Height          =   240
  87.          Index           =   3
  88.          Left            =   135
  89.          TabIndex        =   11
  90.          Top             =   1185
  91.          Width           =   780
  92.       End
  93.       Begin SSOption ComPort 
  94.          Caption         =   "COM&3:"
  95.          ForeColor       =   &H00000000&
  96.          Height          =   240
  97.          Index           =   2
  98.          Left            =   135
  99.          TabIndex        =   10
  100.          Top             =   885
  101.          Width           =   780
  102.       End
  103.       Begin SSOption ComPort 
  104.          Caption         =   "COM&2:"
  105.          ForeColor       =   &H00000000&
  106.          Height          =   240
  107.          Index           =   1
  108.          Left            =   135
  109.          TabIndex        =   9
  110.          Top             =   585
  111.          Width           =   780
  112.       End
  113.       Begin SSOption ComPort 
  114.          Caption         =   "COM&1:"
  115.          ForeColor       =   &H00000000&
  116.          Height          =   240
  117.          Index           =   0
  118.          Left            =   135
  119.          TabIndex        =   8
  120.          Top             =   285
  121.          Width           =   780
  122.       End
  123.    End
  124.    Begin TextBox DialString 
  125.       Height          =   300
  126.       Left            =   375
  127.       TabIndex        =   6
  128.       Text            =   "ATDT 1 303 494-4774"
  129.       Top             =   1710
  130.       Width           =   4080
  131.    End
  132.    Begin Label Status 
  133.       Alignment       =   1  'Right Justify
  134.       BackStyle       =   0  'Transparent
  135.       Height          =   240
  136.       Left            =   1125
  137.       TabIndex        =   13
  138.       Top             =   15
  139.       Width           =   3300
  140.    End
  141.    Begin Label Label1 
  142.       BackStyle       =   0  'Transparent
  143.       Caption         =   "Modem Dial String"
  144.       Height          =   210
  145.       Index           =   1
  146.       Left            =   225
  147.       TabIndex        =   5
  148.       Top             =   1440
  149.       Width           =   2145
  150.    End
  151.    Begin Label Label1 
  152.       BackStyle       =   0  'Transparent
  153.       Caption         =   "Time Zone"
  154.       Height          =   240
  155.       Index           =   0
  156.       Left            =   195
  157.       TabIndex        =   2
  158.       Top             =   165
  159.       Width           =   1320
  160.    End
  161. End
  162. Option Explicit
  163.  
  164. Dim ControlsDisabled As Integer
  165. Dim InString As String
  166. Dim TString As String
  167. Dim Aborted As Integer
  168.  
  169. '
  170.                              'DESCRIPTION OF THE
  171.                  'AUTOMATED COMPUTER TELEPHONE SERVICE (ACTS)
  172. '
  173. '
  174. 'The following is transmitted (at 1200 Baud) after completion of the
  175. 'telephone connection.
  176. '
  177.              '? = HELP
  178.              'National Institute of Standards and Technology
  179.              'Telephone Time Service
  180. '
  181.                                      'D  L D
  182.               'MJD  YR MO DA H  M  S  ST S UT1 msADV        <OTM>
  183.              '47999 90-04-18 21:39:15 50 0 +.1 045.0 UTC(NIST) *
  184.              '47999 90-04-18 21:39:16 50 0 +.1 045.0 UTC(NIST) *
  185.              '47999 90-04-18 21:39:17 50 0 +.1 045.0 UTC(NIST) *
  186.              '47999 90-04-18 21:39:18 50 0 +.1 045.0 UTC(NIST) *
  187.              '47999 90-04-18 21:39:19 50 0 +.1 037.6 UTC(NIST) #
  188.              '47999 90-04-18 21:39:20 50 0 +.1 037.6 UTC(NIST) #
  189.              'etc..etc...etc.......
  190. '
  191. 'UTC = Universal Time Coordinated, the official world time referred to the
  192. 'zero meridian.
  193. '_________________________________________________________________________
  194. '
  195. 'DST = Daylight savings time characters, valid for the continental U.S., are
  196. 'set as follows:
  197.   '00 = We are on standard time (ST).    50 = We are on DST.
  198.   '99 to 51 = Now on ST, go to DST when your local time is 2:00 am and the
  199.     'count is 51.  The count is decremented daily at 00 (UTC).
  200.   '49 to 01 = Now on DST, go to ST when your local time is 2:00 am and the
  201.     'count is 01.  The count is decremented daily at 00 (UTC).
  202. 'The two DST characters provide up to 48 days advance notice of a change in
  203. 'time.  The count remains at 00 or 50 at other times.
  204. '_________________________________________________________________________
  205. '
  206. 'LS = Leap second flag is set to "1" to indicate that a leap second is to be
  207. 'added as 23:59:60 (UTC) on the last day of the current UTC month.  The LS
  208. 'flag will be reset to "0" starting with 23:59:60 (UTC).  The flag will
  209. 'remain on for the entire month before the second is added.  Leap seconds
  210. 'are added as needed at the end of any month.  Usually June and/or December
  211. 'are chosen.
  212. '
  213. '__________________________________________________________________________
  214. ''
  215. 'DUT1 = Approximate difference between earth rotation time (UT1) and UTC, in
  216. 'steps of 0.1 second.         DUT1 = UT1 - UTC
  217. '___________________________________________________________________________
  218. ''
  219. 'MJD = Modified Julian Date, often used to tag certain scientific data.
  220. '___________________________________________________________________________
  221. ''
  222. 'The full time format is sent at 1200 Baud, 8 bit, 1 stop, no parity.
  223. 'The format at 300 Baud is also 8 bit, 1 stop, no parity.
  224. 'At 300 Baud the MJD and DUT1 values are deleted and the
  225. 'time is transmitted only on even seconds.
  226. '___________________________________________________________________________
  227. ''
  228. 'Maximum on line time will be 56 seconds.  If all lines are busy at any time,
  229. 'the oldest call will be terminated if it has been on line more than 28
  230. 'seconds, else, the call that first reaches 28 seconds will be terminated.
  231. '___________________________________________________________________________
  232. ''
  233. 'Current time is valid at the "on-time" marker (OTM), either "*" or "#".
  234. 'The nominal on-time marker (*) will be transmitted 45 ms early to account
  235. 'for the 8 ms required to send 1 character at 1200 Baud, plus an additional
  236. '7 ms for delay from NIST to the user, and approximately 30 ms "scrambler"
  237. 'delay inherent in 1200 Baud modems.  If the caller echoes all characters,
  238. 'NIST will measure the round trip delay and advance the on-time marker so
  239. 'that the midpoint of the stop bit arrives at the user on time.  The amount
  240. 'of msADV will reflect the actual required advance in milliseconds and the
  241. 'OTM will be a "#".  The NIST system requires 4 or 5 consecutive delay
  242. 'measurements which are consistent before switching from "*" to "#".
  243. 'If the user has a 1200 Baud modem with the same internal delay as that used
  244. 'by NIST, then the "#" OTM should arrive at the user within +-2 ms of the
  245. 'correct time.  However, NIST has studied different brands of 1200 Baud
  246. 'modems and found internal delays from 24 ms to 40 ms and offsets of the
  247. '"#" OTM of +-10 ms.  For many computer users, +-10 ms accuracy should be
  248. 'more than adequate since many computer internal clocks can only be set with
  249. 'granularity of 20 to 50 ms.  In any case, the repeatability of the offset
  250. 'for the "#" OTM should be within +-2 ms, if the dial-up path is reciprocal
  251. 'and the user doesn't change the brand or model of modem used. This should
  252. 'be true even if the dial-up path on one day is a land-line of less than
  253. '40 ms (one way) and on the next day is a satellite link of 260 to 300 ms.
  254. 'In the rare event that the path is one way by satellite and the other way
  255. 'by land line with a round trip measurement in the range of 90 to 260 ms,
  256. 'the OTM will remain a "*" indicating 45 ms advance.
  257. '___________________________________________________________________________
  258. '''
  259. 'For user comments write:
  260. 'NIST-ACTS
  261. 'Time and Frequency Division
  262. 'Mail Stop 524
  263. '325 Broadway
  264. 'Boulder, CO  80303
  265. '
  266. 'Software for setting (PC)DOS compatable machines is available
  267. 'on a 360-kbyte diskette for $35.00 from:
  268. 'NIST Office of Standard Reference Materials
  269. 'B311-Chemistry Bldg, NIST, Gaithersburg, MD, 20899, (301) 975-6776
  270. '
  271. '--------------------------------------------------------------------------
  272.  
  273. Sub Command1_Click (Index As Integer)
  274. Dim StartTime As Double
  275. Dim I As Integer
  276. Dim NewD As Double
  277. Dim OldD As Double
  278. Dim DSTFlag As String
  279. Dim OffBy As String
  280.  
  281. If Index = 0 Then  'Reset Defaults
  282.    ResetDefaults
  283.    Status.Caption = ""
  284. End If
  285.  
  286. If Index = 1 Then  'Dial
  287.    SaveModemSettings
  288.    Aborted = False
  289.    Status.Caption = ""
  290.  
  291.    Command1(0).Enabled = False
  292.    Command1(1).Enabled = False
  293.    TimeZone.Enabled = False
  294.    DST.Enabled = False
  295.    DialString.Enabled = False
  296.    Frame3D1.Enabled = False
  297.    ControlsDisabled = True
  298.    On Local Error GoTo ErrHndl
  299.    For I% = 0 To 3
  300.      If ComPort(I%).Value Then comm1.CommPort = I% + 1
  301.    Next I%
  302.    If Aborted Then Exit Sub
  303.    comm1.Settings = "1200,N,8,1"
  304.    If Aborted Then Exit Sub
  305.    comm1.PortOpen = True
  306.    If Aborted Then Exit Sub
  307.    comm1.Output = DialString.Text + Chr$(13) + Chr(10)
  308.    StartTime = Timer
  309.    LastTime = 0
  310.    Do
  311.       DoEvents
  312.       If LastTime <> Int(Timer) Then
  313.          If Not Aborted Then Status.Caption = "Connecting - " + Format$(75 - Int(Timer - StartTime)) + " seconds until timeout."
  314.          LastTime = Int(Timer)
  315.       End If
  316.    Loop Until comm1.InBufferCount >= 600 Or ((Timer - StartTime) > 75) Or Aborted
  317.    If Aborted Then Exit Sub
  318.    
  319.    If (Timer - StartTime) > 75 Then
  320.          Status.Caption = "Timed out."
  321.          Exit Sub
  322.    End If
  323.    
  324.    Status.Caption = "Setting time."
  325.    InString$ = comm1.Input
  326.    If Aborted Then Exit Sub
  327.    InString$ = Mid$(InString$, InStr(InString$, "*") + 1, 80)
  328.     
  329.  
  330.    NewD = DateValue(Mid$(InString$, 12, 2) + "/" + Mid$(InString$, 15, 2) + "/" + Mid$(InString$, 9, 2))
  331.    NewD = NewD + TimeValue(Mid$(InString$, 18, 8))
  332.    
  333.    NewD = NewD - (TimeZone.ListIndex - 11) * (1 / 24)
  334.    DSTFlag$ = Mid$(InString$, 27, 2)
  335.    'If ((DSTFlag >= "01") And (DSTFlag <= "50")) Then
  336.    '   NewD = NewD - (1 / 24)
  337.    'End If
  338.    If DST.Value Then
  339.       NewD = NewD + (1 / 24)
  340.    End If
  341.    OldD = Date + Time
  342.    If Year(NewD) >= 1993 Then
  343.       Date = Format$(NewD, "mm/dd/yy")
  344.       Time = Format$(NewD, "hh:mm:ss")
  345.       If OldD > NewD Then
  346.          OffBy = "fast"
  347.       Else
  348.          OffBy = "slow"
  349.       End If
  350.       MsgBox "Time set to " + Format$(NewD, "hh:mm:ss") + ".  Clock was " + OffBy$ + " by " + Format$(Abs(NewD - OldD), "hh:mm:ss") + "."
  351.       Screen.MousePointer = 11
  352.       AtomicTimeWasSet = True
  353.       Status.Caption = "Time set."
  354.    Else
  355.       MsgBox "Error getting date and time."
  356.    End If
  357.    
  358.    If Aborted Then Exit Sub
  359.    Screen.MousePointer = 11
  360.    HangUp
  361.    If Aborted Then Exit Sub
  362.    On Local Error Resume Next
  363.    
  364.    Screen.MousePointer = 0
  365.    Unload Atomic
  366.  
  367. End If
  368.  
  369. If Index = 2 Then  'Cancel
  370.    If ControlsDisabled Then
  371.       HangUp
  372.       EnableControls
  373.       Aborted = True
  374.       Status.Caption = "Aborted."
  375.    Else
  376.       Unload Atomic
  377.    End If
  378. End If
  379.  
  380. EnableControls
  381. Exit Sub
  382.  
  383.  
  384. ErrHndl:
  385. MsgBox "Error: " + Error(Err)
  386. EnableControls
  387. Exit Sub
  388. End Sub
  389.  
  390. Sub EnableControls ()
  391.    Command1(0).Enabled = True
  392.    Command1(1).Enabled = True
  393.    TimeZone.Enabled = True
  394.    DST.Enabled = True
  395.    DialString.Enabled = True
  396.    Frame3D1.Enabled = True
  397.    ControlsDisabled = False
  398. End Sub
  399.  
  400. Sub Form_Load ()
  401. Atomic.Left = Settings.Left + (Settings.Width / 2) - (Atomic.Width / 2)
  402. Atomic.Top = Settings.Top + (Settings.Height / 2) - (Atomic.Height / 2)
  403.  
  404. TimeZone.AddItem "Greenwich + 11"
  405. TimeZone.AddItem "Greenwich + 10"
  406. TimeZone.AddItem "Greenwich + 9"
  407. TimeZone.AddItem "Greenwich + 8"
  408. TimeZone.AddItem "Greenwich + 7"
  409. TimeZone.AddItem "Greenwich + 6"
  410. TimeZone.AddItem "Greenwich + 5"
  411. TimeZone.AddItem "Greenwich + 4"
  412. TimeZone.AddItem "Greenwich + 3"
  413. TimeZone.AddItem "Greenwich + 2"
  414. TimeZone.AddItem "Greenwich + 1"
  415. TimeZone.AddItem "Greenwich"
  416. TimeZone.AddItem "Greenwich - 1"
  417. TimeZone.AddItem "Greenwich - 2"
  418. TimeZone.AddItem "Greenwich - 3"
  419. TimeZone.AddItem "Atlantic Standard Time (4)"
  420. TimeZone.AddItem "Eastern Standard Time"
  421. TimeZone.AddItem "Central Time"
  422. TimeZone.AddItem "Mountain Time"
  423. TimeZone.AddItem "Pacific Time"
  424. TimeZone.AddItem "Yukon Standard Time"
  425. TimeZone.AddItem "Alaska-Hawaii Standard Time"
  426. TimeZone.AddItem "Nome Standard Time"
  427. TimeZone.AddItem "Greenwich - 12"
  428. ResetDefaults
  429. LoadModemSettings
  430. 'Atomic.Show 1
  431. 'Command1(1).SetFocus
  432. End Sub
  433.  
  434. Sub HangUp ()
  435.    Dim StartTime As Double
  436.    Dim I As Integer
  437.    Dim Ret As Integer
  438.  
  439.    'Josh version  -
  440.    'comm1.PortOpen = False
  441.    'Exit Sub
  442.  
  443.  
  444.  
  445.  
  446.    'Beep
  447.    On Local Error GoTo ErrHndl2
  448.    'comm1.Output = "+++"
  449.    'StartTime = Timer
  450.    'While Timer - StartTime < .5
  451.    '  DoEvents
  452.    'Wend
  453.    'comm1.Output = "ATH0" + Chr$(13) + Chr(10)
  454.    comm1.Output = ""
  455.    For I% = 1 To 3
  456.    StartTime = Timer
  457.    TString$ = comm1.Input
  458.    comm1.Output = "+"
  459.    While Timer - StartTime < .25
  460.      DoEvents
  461.    Wend
  462.    Next I%
  463.  
  464.    'Do
  465.    '   DoEvents
  466.    'Loop Until comm1.InBufferCount >= 2
  467.  
  468.    StartTime = Timer
  469.    While Timer - StartTime < 3#
  470.      DoEvents
  471.    Wend
  472.    
  473.    TString$ = comm1.Input
  474.    comm1.Output = "ATH0" + Chr(13) + Chr(10)
  475.    StartTime = Timer
  476.    Do
  477.       DoEvents
  478.    Loop Until comm1.InBufferCount >= 2 Or (Timer - StartTime) > 5
  479.    TString$ = comm1.Input
  480.  
  481.    StartTime = Timer
  482.    While Timer - StartTime < 1#
  483.      DoEvents
  484.    Wend
  485.    
  486.    '3/28/92 version
  487.    comm1.PortOpen = False
  488.    Exit Sub
  489.  
  490.    
  491.    comm1.Output = "+++"
  492.    StartTime = Timer
  493.    While Timer - StartTime < .5
  494.      DoEvents
  495.    Wend
  496.    comm1.Output = "ATH0" + Chr$(13) + Chr(10)
  497.  
  498.    Ret = comm1.DTREnable     'Save current setting
  499.    comm1.DTREnable = True    'Turn DTR on
  500.      DoEvents
  501.    comm1.DTREnable = False   'Turn DTR off
  502.      DoEvents
  503.    comm1.DTREnable = Ret     'Restore old setting
  504.    
  505.    comm1.PortOpen = False
  506.  
  507. ErrHndl2:
  508.   EnableControls
  509.   Exit Sub
  510. End Sub
  511.  
  512. Sub LoadModemSettings ()
  513. Dim lpReturnedString As String * 100
  514. Dim a As Integer
  515.  
  516. lpReturnedString = Space$(100)
  517. a% = MyGetProfileString("AllTheTime", "TimeZoneIndex", "16", lpReturnedString$, 100)
  518. TimeZone.ListIndex = Val(lpReturnedString)
  519.  
  520. a% = MyGetProfileString("AllTheTime", "DST", "0", lpReturnedString$, 100)
  521. DST.Value = Val(lpReturnedString)
  522.  
  523. a% = MyGetProfileString("AllTheTime", "DialString", "ATDT 1 303 494-4774", lpReturnedString$, 100)
  524. DialString.Text = lpReturnedString
  525.  
  526. a% = MyGetProfileString("AllTheTime", "ComPort", "0", lpReturnedString$, 100)
  527. ComPort(Val(lpReturnedString)).Value = True
  528. End Sub
  529.  
  530. Sub ResetDefaults ()
  531.    TimeZone.ListIndex = 16
  532.    DST.Value = 0
  533.    DialString.Text = "ATDT 1 303 494-4774"
  534.    ComPort(0).Value = True
  535.    'LoadModemSettings
  536. End Sub
  537.  
  538. Sub SaveModemSettings ()
  539. Dim a As Integer
  540. Dim M As String
  541. Dim I As Integer
  542.  
  543. a% = WritePrivateProfileString("AllTheTime", "TimeZoneIndex", TimeZone.ListIndex, "ATT.INI")
  544. a% = WritePrivateProfileString("AllTheTime", "DST", DST.Value, "ATT.INI")
  545. a% = WritePrivateProfileString("AllTheTime", "DialString", DialString.Text, "ATT.INI")
  546. M$ = "0"
  547. For I% = 0 To 3
  548.    If ComPort(I%).Value Then M$ = Str$(I%)
  549. Next I%
  550. a% = WritePrivateProfileString("AllTheTime", "ComPort", M$, "ATT.INI")
  551.  
  552. End Sub
  553.  
  554.